package com.example.hotel_lxy.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.example.hotel_lxy.R;
import com.example.hotel_lxy.bean.HelpCenterBean;
import com.ysxsoft.common_base.utils.ViewUtils;

import java.util.List;

public class CourseMenuAdapter extends BaseExpandableListAdapter {
    private Context activity;
    private  List<HelpCenterBean.DataBean.ListBean> list;

    public CourseMenuAdapter(List<HelpCenterBean.DataBean.ListBean> list) {
        this.list = list;
    }

    public CourseMenuAdapter(Context activity ,      List<HelpCenterBean.DataBean.ListBean> list) {
        this.activity = activity;
        this.list = list;
    }

    @Override
    public int getGroupCount() {
         return list == null ? 0 : list.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return list.get(groupPosition).getLists() == null ? 0 : list.get(groupPosition).getLists().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return list.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return list.get(groupPosition).getLists().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }
    //一级数据
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        ViewHolder1 holder1;
        if (convertView == null) {
            convertView = View.inflate(parent.getContext(), R.layout.item_help_activity_one, null);
            holder1 = new ViewHolder1(convertView);
            convertView.setTag(holder1);
        } else {
            holder1 = (ViewHolder1) convertView.getTag();
        }
        holder1.text1.setTextSize(14);
        holder1.text1.setText(list.get(groupPosition).getTitle());
        holder1.view.setVisibility(View.GONE);
        if(isExpanded){
            ViewUtils.setLeft(activity,  holder1.text1, R.mipmap.icon_right);
        }else{
            ViewUtils.setLeft(activity,  holder1.text1, R.mipmap.icon_arrow_down);
        }
        return convertView;

    }
    //二级
    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ViewHolder2 holder2;
        if (convertView == null) {
            convertView = View.inflate(parent.getContext(), R.layout.item_help_activity, null);
            holder2 = new ViewHolder2(convertView);
            convertView.setTag(holder2);
        } else {
            holder2 = (ViewHolder2) convertView.getTag();
        }
        holder2.text1.setTextSize(11);
        holder2.text1.setText(list.get(groupPosition).getLists().get(childPosition).getTitle());
        holder2.view.setVisibility(View.VISIBLE);
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }


    //1组的数据
    public static class ViewHolder1 {


        private final TextView text1;
        private final View view;
        public ViewHolder1(View itemview) {
            text1 = itemview.findViewById(R.id.text1);
            view=itemview.findViewById(R.id.view);
        }

    }

    //2组的数据
    public static class ViewHolder2 {


        private final TextView text1;
        private final View view;
        public ViewHolder2(View itemview) {
            text1 = itemview.findViewById(R.id.text1);
            view=itemview.findViewById(R.id.view);
        }
    }
}
